import request from './index'




export function getAllArticles() {
  return request.get('/article')
}
export function getArticlesByTag(tagId: number) {
  return request.get(`/article/tag/${tagId}`)
}
export function searchArticlesByTitle(keyword: string) {
  return request.get('/article/search', {
    params: { keyword }
  })
}
export function getArticlesByUser(userId: number) {
  return request.get(`/article/user/${userId}`)
}

export function deleteArticle(id: number) {
  return request.delete(`/article/${id}`)
}

export function createArticle(data: {
  title: string
  content: string
  author_id: number
  tag_ids: number[]
}) {
  return request.post('/article', data)
}

export function updateArticle(id: number, data: {
  title: string
  content: string
  tag_ids: number[]
}) {
  console.log('调用 updateArticle 接口：', id, data)
  return request.put(`/article/${id}`, data)
}
export function getArticleDetail(id: number) {
  return request.get(`/article/${id}`)
}
